local EntityFactory = Battle.CreateClass("EntityFactory")
Battle.EntityFactory = EntityFactory
local this = EntityFactory
---@return Battle.Entity
function EntityFactory.CreateHero(modelId,camp,posX,posY,posZ,dirX,dirY,dirZ,param)
    local entity = Battle.Entity.New()
    entity:BaseCreate(param)
    this.UpdateEntity(entity,modelId,Battle.ActorType.Hero,camp,posX,posY,posZ,dirX,dirY,dirZ)
    this.CreateFinished(entity)
    Battle.EventManager.notifyEventListenerAll(Battle.BuffTriggerType.HERO, entity.id,entity)--生成英雄后触发buff
    return entity
end
function EntityFactory.CreateLord(modelId,camp,posX,posY,posZ,dirX,dirY,dirZ)
    local entity = Battle.Entity.New()
    entity:BaseCreate()
    this.UpdateEntity(entity,modelId,Battle.ActorType.Lord,camp,posX,posY,posZ,dirX,dirY,dirZ)
    Battle.ActorManager.AddLord(camp,entity)
    this.CreateFinished(entity)
    return entity
end


---@private
---@param entity Battle.Entity
function EntityFactory.UpdateEntity(entity,modelId,actorType,camp,posX,posY,posZ,dirX,dirY,dirZ)
    entity.modelId = modelId
    entity.id = Battle.IDGenerator.GetId()
    entity.name = DataTable.GetById("t_hero",modelId,"f_HeroName")
    entity.actorType = actorType
    entity.camp = camp
    entity:SetPos(posX,posY,posZ)
    entity:SetForward(dirX,dirY,dirZ)
end
---@private
---@param entity Battle.Entity
function EntityFactory.CreateFinished(entity)
    entity.eventSystem:FireEvent(Battle.Event.ActorInitializeBefore,Battle.EventArgs.EntityArgs:Create(entity))
    Battle.ActorManager.AddActor(entity)
    entity:OnInitialize()
    entity.eventSystem:FireEvent(Battle.Event.ActorCreate,Battle.EventArgs.EntityArgs:Create(entity))
end